package _01_动态数组;

public class _704_二分查找 {

    public static void main(String[] args) {

        int[] dp = {-1, 0, 3, 5, 9, 12};
        _704_二分查找 v = new _704_二分查找();
        System.out.println(v.search(dp, 9));

    }


    public int search(int[] nums, int target) {
        int begin = 0;
        int end = nums.length - 1;
        while (begin <= end) {
            int mid = begin + end >> 1;
            if (nums[mid] > target) {
                end = mid - 1;
            } else if (nums[mid] < target) {
                begin = mid + 1;
            } else {
                return mid;
            }
        }
        return -1;
    }

}
